#!/bin/bash

LOG_FILE="/var/log/application.log"
LAST_CHECKED_LINE=$HOME/.last_checked_line

# 检查日志文件是否有新的错误信息
tail -n $(($(tail -n +1 $LOG_FILE | wc -l) - 1)) $LOG_FILE | grep "ERROR" > /dev/null

if [ $? -eq 0 ]; then
    # 发送邮件报警
    echo "New error detected in log file" | mail -s "Error Alert" admin@example.com
fi

# 更新最后检查的行数
tail -n 1 $LOG_FILE > $LAST_CHECKED_LINE